package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();) {
            conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            conn.setAutoCommit(false);
            String sql = "INSERT INTO users(name,password,nickname,age) " +
                    "VALUES(?,?,?,?)";
            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.setString(1, "张三");
            stmt.setString(2, "123456");
            stmt.setString(3, "张三");
            stmt.setInt(4, 18);

            int count = stmt.executeUpdate();
            System.out.println(count>0?"添加成功":"添加失败");
            conn.commit();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
